home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / usr_22.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  11.9 KB  |  357 lines

  1. *usr_22.txt*    For Vim version 6.0.  Last change: 2001 Sep 03
  2.  
  3.              VIM USER MANUAL - by Bram Moolenaar
  4.  
  5.                Finding the file to edit
  6.  
  7.  
  8. Files can be found everywhere.  So how do you find them?  Vim offers various
  9. ways to browse the directory tree.  There are commands to jump to a file that
  10. is mentioned in another.  And Vim remembers which files have been edited
  11. before.
  12.  
  13. |22.1|    The file explorer
  14. |22.2|    The current directory
  15. |22.3|    Finding a file
  16. |22.4|    The buffer list
  17.  
  18.      Next chapter: |usr_23.txt|  Editing other files
  19.  Previous chapter: |usr_21.txt|  Go away and come back
  20. Table of contents: |usr_toc.txt|
  21.  
  22. ==============================================================================
  23. *22.1*    The file explorer
  24.  
  25. Vim has a plugin that makes it possible to edit a directory.  Try this: >
  26.  
  27.     :edit .
  28.  
  29. Through the magic of autocommands and Vim scripts, the window will be filled
  30. with the contents of the directory.  It looks like this:
  31.  
  32.     " Press ? for keyboard shortcuts ~
  33.     " Sorted by name (.bak,~,.o,.h,.info,.swp,.obj,.orig,.rej at end of list) ~
  34.     "= /home/mool/vim/vim6/runtime/doc/ ~
  35.     ../ ~
  36.     check/ ~
  37.     Makefile ~
  38.     autocmd.txt ~
  39.     change.txt ~
  40.     eval.txt~ ~
  41.     filetype.txt~ ~
  42.     help.txt.info ~
  43.  
  44. You can see these items:
  45. 1.  A comment about using ? to get help for the functionality of the file
  46.     explorer.
  47. 2.  The second line mentions how the items in the directory are listed.  They
  48.     can be sorted in several ways.
  49. 3.  The third line is the name of the current directory.
  50. 4.  The "../" directory item.  This is the parent directory.
  51. 5.  The directory names.
  52. 6.  The ordinary file names.  As mentioned in the second line, some are not
  53.     here but "at the end of the list".
  54. 7.  The less ordinary file names.  You are expected to use these less often,
  55.     therefore they have been moved to the end.
  56.  
  57. If you have syntax highlighting enabled, the different parts are highlighted
  58. to make it easier to spot them.
  59.  
  60. You can use Normal mode Vim commands to move around in the text.  For example,
  61. move to a file and press <Enter>.  Now you are editing that file.  To go back
  62. to the explorer use ":edit ." again.  CTRL-O also works.
  63.    Try using <Enter> while the cursor is on a directory name.  The result is
  64. that the explorer moves into that directory and displays the items found
  65. there.  Pressing <Enter> on the first directory "../" moves you one level
  66. higher.  Pressing "-" does the same thing, without the need to move to the
  67. "../" item first.
  68.  
  69. You can press ? to get short help on the things you can do in the explorer.
  70. This is what you get:
  71.  
  72.     " <enter> : open file or directory ~
  73.     " o : open new window for file/directory ~
  74.     " O : open file in previously visited window ~
  75.     " p : preview the file ~
  76.     " i : toggle size/date listing ~
  77.     " s : select sort field    r : reverse sort ~
  78.     " - : go up one level      c : cd to this dir ~
  79.     " R : rename file       D : delete file ~
  80.     " :help file-explorer for detailed help ~
  81.  
  82. The first few commands are for selecting a file to display.  Depending on what
  83. command you use, the file appears somewhere:
  84.  
  85.     <Enter>        Uses the current window.
  86.     o        Opens a new window.
  87.     O        Uses the previously visited window.
  88.     p        Uses the preview window, and moves the cursor back
  89.             into the explorer window. |preview-window|
  90.  
  91. The following commands are used to display other information:
  92.  
  93.     i        Display the size and date for the file.  Using i again
  94.             will hide the information.
  95.     s        Use the field the cursor is in to sort on.  First
  96.             display the size and date with i.  Then Move the
  97.             cursor to the size of any file and press s.  The files
  98.             will now be sorted on size.  Press s wile the cursor
  99.             is on a date and the items will be sorted on date.
  100.     r        reverse the sorting order (either size or date)
  101.  
  102. There are a few extra commands:
  103.  
  104.     c        Change the current directory to the displayed
  105.             directory.  You can then type an ":edit" command for
  106.             one of the files without prepending the path.
  107.     R        Rename the file under the cursor.  You will be
  108.             prompted for the new name.
  109.     D        Delete the file under the cursor.  You will get a
  110.             prompt to confirm this.
  111.  
  112. ==============================================================================
  113. *22.2*    The current directory
  114.  
  115. Just like the shell, Vim has the concept of a current directory.  Suppose you
  116. are in your home directory and want to edit several files in a directory
  117. "VeryLongFileName".  You could do: >
  118.  
  119.     :edit VeryLongFileName/file1.txt
  120.     :edit VeryLongFileName/file2.txt
  121.     :edit VeryLongFileName/file3.txt
  122.  
  123. To avoid much of the typing, do this: >
  124.  
  125.     :cd VeryLongFileName
  126.     :edit file1.txt
  127.     :edit file2.txt
  128.     :edit file3.txt
  129.  
  130. The ":cd" command changes the current directory.  You can see what the current
  131. directory is with the ":pwd" command: >
  132.  
  133.     :pwd
  134.     /home/Bram/VeryLongFileName
  135.  
  136. Vim remembers the last directory that you used.  Use "cd -" to go back to it.
  137. Example: >
  138.  
  139.     :pwd
  140.     /home/Bram/VeryLongFileName
  141.     :cd /etc
  142.     :pwd
  143.     /etc
  144.     :cd -
  145.     :pwd
  146.     /home/Bram/VeryLongFileName
  147.     :cd -
  148.     :pwd
  149.     /etc
  150.  
  151.  
  152. WINDOW LOCAL DIRECTORY
  153.  
  154. When you split a window, both windows use the same current directory.  When
  155. you want to edit a number of files somewhere else in the new window, you can
  156. make it use a different directory, without changing the current directory in
  157. the other window.  This is called a local directory. >
  158.  
  159.     :pwd
  160.     /home/Bram/VeryLongFileName
  161.     :split
  162.     :lcd /etc
  163.     :pwd
  164.     /etc
  165.     CTRL-W w
  166.     :pwd
  167.     /home/Bram/VeryLongFileName
  168.  
  169. So long as no ":lcd" command has been used, all windows share the same current
  170. directory.  Doing a ":cd" command in one window will also change the current
  171. directory of the other window.
  172.    For a window where ":lcd" has been used a different current directory is
  173. remembered.  Using ":cd" or ":lcd" in other windows will not change it.
  174.    When using a ":cd" command in a window that uses a different current
  175. directory, it will go back to using the shared directory.
  176.  
  177. ==============================================================================
  178. *22.3*    Finding a file
  179.  
  180. You are editing a C program that contains this line:
  181.  
  182.     #include "inits.h" ~
  183.  
  184. You want to see what is in that "inits.h" file.  Move the cursor on the name
  185. of the file and type: >
  186.  
  187.     gf
  188.  
  189. Vim will find the file and edit it.
  190.    What if the file is not in the current directory?  Vim will use the 'path'
  191. option to find the file.  This option is a list of directory names where to
  192. look for your file.
  193.    Suppose you have your include files located in "c:/prog/include".  This
  194. command will add it to the 'path' option: >
  195.  
  196.     :set path+=c:/prog/include
  197.  
  198. This directory is an absolute path.  No matter where you are, it will be the
  199. same place.  What if you have located files in a subdirectory, below where the
  200. file is?  Then you can specify a relative path name.  This starts with a dot:
  201. >
  202.     :set path+=./proto
  203.  
  204. This tells Vim to look in the directory "proto", below the directory where the
  205. file in which you use "gf" is.  Thus using "gf" on "inits.h" will make Vim
  206. look for "proto/inits.h", starting in the directory of the file.
  207.    Without the "./", thus "proto", Vim would look in the "proto" directory
  208. below the current directory.  And the current directory might not be where the
  209. file that you are editing is located.
  210.  
  211. The 'path' option allows specifying the directories where to search for files
  212. in many more ways.  See the help on the 'path' option.
  213.    The 'isfname' option is used to decide which characters are included in the
  214. file name, and which ones are not (e.g., the " character in the example
  215. above).
  216.  
  217. When you know the file name, but it's not to be found in the file, you can
  218. type it: >
  219.  
  220.     :find inits.h
  221.  
  222. Vim will then use the 'path' option to try and locate the file.  This is the
  223. same as the ":edit" command, except for the use of 'path'.
  224.  
  225. To open the found file in a new window use CTRL-W f instead of "gf", or use
  226. ":sfind" instead of ":find".
  227.  
  228. ==============================================================================
  229. *22.4*    The buffer list
  230.  
  231. The Vim editor uses the term buffer to describe a file being edited.
  232. Actually, a buffer is a copy of the file that you edit.  When you finish
  233. changing the buffer, you write the contents of the buffer to the file.
  234. Buffers not only contain file contents, but also all the marks, settings, and
  235. other stuff that goes with it.
  236.  
  237.  
  238. HIDDEN BUFFERS
  239.  
  240. Suppose you are editing the file one.txt and need to edit the file two.txt.
  241. You could simply use ":edit two.txt", but since you made changes to one.txt
  242. that won't work.  You also don't want to write one.txt yet.  Vim has a
  243. solution for you: >
  244.  
  245.     :hide edit two.txt
  246.  
  247. The buffer "one.txt" disappears from the screen, but Vim still knows that you
  248. are editing this buffer, so it keeps the modified text.  This is called a
  249. hidden buffer: The buffer contains text, but you can't see it.
  250.    The ":hide" command argument is another command.  It makes that command
  251. behave like the 'hidden' option was set.  You could also set this option
  252. yourself.  The effect is that when any buffer is abandoned, it becomes hidden.
  253.    Be careful!  When you have hidden buffers with changes, don't exit Vim
  254. without making sure you have saved all the buffers.
  255.  
  256.  
  257. INACTIVE BUFFERS
  258.  
  259.    When a buffer has been used once, Vim remembers some information about it.
  260. When it is not displayed in a window and it is not hidden, it is still in the
  261. buffer list.  This is called an inactive buffer.  Overview:
  262.  
  263.    Active        Appears in a window, text loaded.
  264.    Hidden        Not in a window, text loaded.
  265.    Inactive        Not in a window, no text loaded.
  266.  
  267. The inactive buffers are remembered, because Vim keeps information about them,
  268. like marks.  And remembering the file name is useful too, so that you can see
  269. which files you have edited.  And edit them again.
  270.  
  271.  
  272. LISTING BUFFERS
  273.  
  274. View the buffer list with this command: >
  275.  
  276.     :buffers
  277.  
  278. A command which does the same, is not so obvious to list buffers, but is much
  279. shorter to type: >
  280.  
  281.     :ls
  282.  
  283. The output could look like this:
  284.  
  285.   1 #h    "help.txt"            line 62 ~
  286.   2 %l+    "usr_21.txt"            line 1 ~
  287.   3    "usr_toc.txt"            line 1 ~
  288.  
  289. The first column contains the buffer number.  You can use this to edit the
  290. buffer without having to type the name, see below.
  291.    After the buffer number come the flags.  Then the name of the file
  292. and the line number where the cursor was the last time.
  293.    The flags that can appear are these (from left to right):
  294.  
  295.     u    Buffer is unlisted |unlisted-buffer|.
  296.      %    Current buffer.
  297.      #    Alternate buffer.
  298.       l    Buffer is loaded and displayed.
  299.       h    Buffer is loaded but hidden.
  300.        =    Buffer is read-only.
  301.        -    Buffer is not modifiable, the 'modifiable' option is off.
  302.         +    Buffer has been modified.
  303.  
  304.  
  305. EDITING A BUFFER
  306.  
  307. You can edit a buffer by its number.  That avoids having to type the file
  308. name: >
  309.  
  310.     :buffer 2
  311.  
  312. But the only way to know the number is by looking in the buffer list.  You can
  313. use the name, or part of it, instead: >
  314.  
  315.     :buffer help
  316.  
  317. Vim will find a best match for the name you type.  If there is only one
  318. buffer that matches the name, it will be used.  In this case "help.txt".
  319.    To open a buffer in a new window: >
  320.  
  321.     :sbuffer 3
  322.  
  323. This works with a name as well.
  324.  
  325.  
  326. USING THE BUFFER LIST
  327.  
  328. You can move around in the buffer list with these commands:
  329.  
  330.     :bnext        go to next buffer
  331.     :bprevious    go to previous buffer
  332.     :bfirst        go to the first buffer
  333.     :blast        go to the last buffer
  334.  
  335. To remove a buffer from the list, use this command: >
  336.  
  337.     :bdelete 3
  338.  
  339. Again, this also works with a name.
  340.    If you delete a buffer that was active (visible in a window), that window
  341. will be closed.  If you delete the current buffer, the current window will be
  342. closed.  If it was the last window, Vim will find another buffer to edit.  You
  343. can't be editing nothing!
  344.  
  345.     Note:
  346.     Even after removing the buffer with ":bdelete" Vim still remembers it.
  347.     It's actually made "unlisted", it no longer appears in the list from
  348.     ":buffers".  The ":buffers!" command will list unlisted buffers (yes,
  349.     Vim can do the impossible).  To really make Vim forget about a buffer,
  350.     use ":bwipe".  Also see the 'buflisted' option.
  351.  
  352. ==============================================================================
  353.  
  354. Next chapter: |usr_23.txt|  Editing other files
  355.  
  356. Copyright: see |manual-copyright|  vim:tw=78:ts=8:ft=help:norl:
  357.